using ImportPlcPointPosition.Enums;
using SqlSugar;
using ImportPlcPointPosition.Extensions;

namespace ZR.Model.Models.ProductionControl
{
    /// <summary>
    /// PLC配置表
    /// </summary>
    [SugarTable("plc_config")]
    public class PlcConfig : BaseEntity
    {
        

        public PlcConfig()
        {
            var btnSave = new AntdUI.CellButton(eOperateBtnType.SaveBtn.ToString(), eOperateBtnType.SaveBtn.GetDisplayDescription(), AntdUI.TTypeMini.Info);
            btnSave.IconSvg = "SaveOutlined";
            var btnDelete = new AntdUI.CellButton(eOperateBtnType.DeleteBtn.ToString(), eOperateBtnType.DeleteBtn.GetDisplayDescription(), AntdUI.TTypeMini.Error);
            btnDelete.IconSvg = "DeleteOutlined";
            _Operate = new AntdUI.CellLink[] { btnSave, btnDelete };
        }


        /// <summary>
        /// Id
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        /// <summary>
        /// 产线代号
        /// </summary>
        [SugarColumn(ColumnName = "production_line_code")]
        public string ProductionLineCode { get; set; }

        /// <summary>
        /// 工位代号
        /// </summary>
        [SugarColumn(ColumnName = "workstation_code")]
        public string WorkstationCode { get; set; }

        public string Remark { get; set; } = string.Empty;

        /// <summary>
        /// PLC类型
        /// </summary>
        [SugarColumn(ColumnName = "plc_type")]
        public string PlcType { get; set; } = string.Empty;

        /// <summary>
        /// PLC地址
        /// </summary>
        [SugarColumn(ColumnName = "plc_address")]
        public string PlcAddress { get; set; } = string.Empty;

        /// <summary>
        /// CPU类型
        /// </summary>
        [SugarColumn(ColumnName = "cpu_type")]
        public string CpuType { get; set; } = "1200";

        /// <summary>
        /// 插槽号
        /// </summary>
        [SugarColumn(ColumnName = "slot_number")]
        public int SlotNumber { get; set; } = 1;

        /// <summary>
        /// 机架号
        /// </summary>
        [SugarColumn(ColumnName = "rack_number")]
        public int RackNumber { get; set; } = 0;

        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "creation_time")]
        public DateTime? CreationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(ColumnName = "creator_name")]
        public string CreatorName { get; set; } = string.Empty;

        /// <summary>
        /// 排序
        /// </summary>
        [SugarColumn(ColumnName = "sort_id")]
        public int SortId { get; set; }


        private bool _IsEnabled;
        /// <summary>
        /// 是否启用
        /// </summary>
        [SugarColumn(ColumnName = "is_enabled")]
        public bool IsEnabled {
            get => _IsEnabled; 
            set 
            {
                _IsEnabled = value;
                base.OnPropertyChanged();
                //OnPropertyChanged("IsEnabled");
            } 
        }

        private bool _AgvEnable;
        public bool AgvEnable
        {
            get => _AgvEnable;
            set
            {
                _AgvEnable = value;
                base.OnPropertyChanged();
                //OnPropertyChanged("AgvEnable");
            }
        }


        #region IsIgnore
        AntdUI.CellLink[] _Operate;
        /// <summary>
        /// 操作
        /// </summary>
        [SugarColumn(IsIgnore =true)]
        public AntdUI.CellLink[] Operate
        {
            get => _Operate;
            set
            {
                _Operate = value;
                base.OnPropertyChanged();
                //OnPropertyChanged("Operate");
            }
        }

        private bool _IsCheck;
        [SugarColumn(IsIgnore = true)]
        public bool IsCheck {
            get => _IsCheck;
            set {
                _IsCheck = value;
                base.OnPropertyChanged();
                //OnPropertyChanged("AgvEnable");
            }
        }

        [SugarColumn(IsIgnore = true)]
        public string Memo {
            get => $"{this.ProductionLineCode}-{this.WorkstationCode}";
        }
        #endregion
    }
}